using System;
using System.Collections.Generic;
using System.Text;

using NUnit.Framework;
using System.Reflection;
using System.Xml;
using System.IO;

namespace HabilisDesign.Iota.UnitTests
{
    [TestFixture]
    public class TwitterGatewayTests
    {
		public XmlDocument UnpackDocument( string documentName )
		{
			XmlDocument document = new XmlDocument();
			using ( Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream( documentName ) )
            {
				document.Load( stream );
				stream.Close();
            }
			return document;
		}

        [Test]
        public void TestGetUpdatesReturnsWebClient()
        {
            TwitterGateway gateway = new TwitterGateway( "davidmohara", "thefly" );
            string updates = gateway.GetStatusUpdates( DateTime.MinValue );
            Assert.IsNotNull( updates );
        }

        [Test]
		public void TestUpdateCollectionAddsAllStatus()
		{
			TwitterGateway gateway = new TwitterGateway();
			XmlDocument document = UnpackDocument( "HabilisDesign.Iota.UnitTests.IncomingStatus.xml" );
			string updates = document.OuterXml;
			StatusCollection testCollection = new StatusCollection();
			gateway.UpdateCollection( testCollection, updates, false );
			Assert.AreEqual( 20, testCollection.Count );
		}

		[Test]
		public void TestUpdateCollectionHandlesHtmlDocument()
		{
			TwitterGateway gateway = new TwitterGateway();
			XmlDocument document = UnpackDocument( "HabilisDesign.Iota.UnitTests.InvalidUpdate.xml" );
			string updates = document.OuterXml;
			StatusCollection testCollection = new StatusCollection();
			gateway.UpdateCollection( testCollection, updates, false );
			Assert.AreEqual( 0, testCollection.Count );
		}

    } // end class

} // end namespace
